package com.elong.android.specialhouse.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.elong.android.specialhouse.R;
import com.elong.android.specialhouse.entity.response.HouseCommentltem;
import com.elong.android.specialhouse.ui.CircleImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.util.List;

/**
 * 
 * @ClassName: ApartmentCommentListAdapter
 * @Description: 更多评价页列表
 * @author: lin.chai
 * @date:2015-08-10
 */
public class ApartmentCommentListAdapter extends BaseAdapter {

	protected ImageLoader mImageLoader = ImageLoader.getInstance();
	private DisplayImageOptions mOptions;

	private List<HouseCommentltem> mCommentsListData;

	public ApartmentCommentListAdapter(List<HouseCommentltem> list) {
		this.mCommentsListData = list;
		mOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_launcher)
				.showStubImage(R.drawable.ic_launcher).imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
				.cacheInMemory().cacheOnDisc().build();
	}

	@Override
	public int getCount() {
		return mCommentsListData.size();
	}

	@Override
	public Object getItem(int position) {
		return mCommentsListData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_apartment_comment_list, null);
			holder = new ViewHolder();
			holder.imageView = (CircleImageView) convertView.findViewById(R.id.comment_user_image);
			holder.userName=(TextView) convertView.findViewById(R.id.comment_user_name);
			holder.commentDate=(TextView) convertView.findViewById(R.id.comment_date);
			holder.commentScore=(TextView) convertView.findViewById(R.id.comment_score);
			holder.commentContent=(TextView) convertView.findViewById(R.id.comment_content);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		HouseCommentltem info = mCommentsListData.get(position);

		mImageLoader.displayImage(info.getSenderHeadUrl(), holder.imageView, mOptions);
        holder.userName.setText(info.getSenderName());
        holder.commentScore.setText(info.getStar()+"");
        holder.commentContent.setText(info.getContent());
        holder.commentDate.setText(info.getTimestamp().substring(0, 10));

		return convertView;
	}

	private class ViewHolder {
		public CircleImageView imageView;
		public TextView userName;
		public TextView commentDate;
		public TextView commentScore;
		public TextView commentContent;
	}
}
